/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipAppeal;
import com.sasis.dao.VipAppealDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipAppealDaoiBatis extends BaseDaoiBATIS implements VipAppealDao {

    /**
     * @see com.sasis.dao.VipAppealDao#getVipAppeals(com.sasis.model.VipAppeal)
     */
    public List getVipAppeals(final VipAppeal vipAppeal) {
          return getSqlMapClientTemplate().queryForList("getVipAppeals", vipAppeal);
    }

    /**
     * @see com.sasis.dao.VipAppealDao#getVipAppeal(Integer id)
     */
    public VipAppeal getVipAppeal(Integer id) {
        VipAppeal vipAppeal = (VipAppeal) getSqlMapClientTemplate().queryForObject("getVipAppeal", id);

        if (vipAppeal == null) {
            throw new ObjectRetrievalFailureException(VipAppeal.class, id);
        }

        return vipAppeal;
    }

    /**
     * @see com.sasis.dao.VipAppealDao#saveVipAppeal(VipAppeal vipAppeal)
     */    
    public void saveVipAppeal(final VipAppeal vipAppeal) {
        Integer id = vipAppeal.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipAppeal", vipAppeal);
        } else {
            getSqlMapClientTemplate().update("updateVipAppeal", vipAppeal);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipAppeal.class, id);
        }
    }

    /**
     * @see com.sasis.dao.VipAppealDao#removeVipAppeal(Integer id)
     */
    public void removeVipAppeal(VipAppeal vipAppeal) {
        getSqlMapClientTemplate().update("deleteVipAppeal",  vipAppeal);
    }
}
